/**
 * File Name	: BaseDaoImpl.java
 * Author		: adelwin
 * Create Date	: 13-Apr-2011:PM 11:43:18
 *
 * Copyright (c) 2011 adelwin. All Rights Reserved. <BR>
 * <BR>
 * This software contains confidential and proprietary information of
 * Adelwin. ("Confidential Information").<BR>
 * <BR>
 * Such Confidential Information shall not be disclosed and it shall
 * only be used in accordance with the terms of the license agreement
 * entered into with Solveware Independent; other than in accordance with the written
 * permission of Solveware Independent. <BR>
 *
 */
package com.uobgroup.cmt.base.dao.impl;

import java.sql.SQLException;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

import com.uobgroup.cmt.base.dao.IBaseTargetDao;
import com.uobgroup.cmt.base.exception.BaseException;
import com.uobgroup.cmt.base.model.BaseModel;
import com.uobgroup.cmt.base.query.BaseQuery;

/**
 * @author adelwin
 *
 */
public class BaseTargetDaoImpl<M extends BaseModel> extends NamedParameterJdbcDaoSupport implements IBaseTargetDao<M> {
	protected Logger logger = Logger.getLogger(BaseTargetDaoImpl.class);
	private BaseQuery query;

	@Override
	public BaseQuery getQuery() {
		return query;
	}

	@Override
	public void setQuery(BaseQuery query) {
		this.query = query;
	}
	
	@Override
	public void insert(M rowItem) throws SQLException, BaseException {
		logger.debug("creating sql parameter source");
		SqlParameterSource sqlParameterSource = new BeanPropertySqlParameterSource(rowItem);
		logger.debug("executing query");
		this.getNamedParameterJdbcTemplate().update(this.query.getQuery(), sqlParameterSource);
	}

}
